package com.jz.stockidentificationclass.conroller;

//import com.jz.subclass.test.SubStatusEnum;

import com.jz.stockidentificationclass.model.StockidentificationAddVo;
import com.jz.stockidentificationclass.model.StockidentificationSelectVo;
import com.jz.stockidentificationclass.model.StockidentificationUpdateStatusVo;
import com.jz.stockidentificationclass.model.StockidentificationUpdateVo;
import com.jz.stockidentificationclass.service.StockidentificationService;
import com.jz.util.ResultBuildVo;
import com.jz.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * Created by WISE on 2021/12/26.
 */
@RestController
@CrossOrigin//开启跨域
public class StockidentificationController {


    //1.首页分页
    @Autowired
    private StockidentificationService stockidentificationService;

    @PostMapping("warehouseTag/queryPage")
    public ResultVo firstPage(@RequestBody StockidentificationSelectVo stockidentificationSelectVo) {
        ResultVo resultVo = stockidentificationService.firstPage(stockidentificationSelectVo);

        return resultVo;
    }

    //2.新增
    @PostMapping("warehouseTag/add")
    @Transactional
    public ResultVo add(@RequestBody @Valid StockidentificationAddVo partAddVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = stockidentificationService.addpartClass(partAddVO);
        return resultVo;
    }
//
////    //3.修改
////    @GetMapping("queryById")
////    @Transactional
////    public ResultVo queryById(Integer id) {
////
////        if (id == null) {
////            return ResultBuildVo.error("ID不能为空");
////        }
////        return stockidentificationService.queryById(id);
////    }
//
//
   @PostMapping("warehouseTag/update")
    public ResultVo update(@RequestBody @Valid StockidentificationUpdateVo partUpdateVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
       return stockidentificationService.updateSubClass(partUpdateVo);
   }

    @PostMapping("warehouseTag/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid StockidentificationUpdateStatusVo partUpdateStatusVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return stockidentificationService.updateStatus(partUpdateStatusVo);
    }

}



